import React, { Component } from "react";
import { Redirect, Switch } from "react-router-dom";
import storeutil from "../../util/storeutil";
import { Route } from "react-router";
import { Layout } from "antd";
import Home from "../home/home";
import Category from "../category/category";
import Product from "../product/product";
import Role from "../role/role";
import Line from "../charts/line";
import Pie from "../charts/pie";
import Bar from "../charts/bar";
import Leftnav from "../../components/leftnav/leftnav";
import User from "../user/user";
import Header from "../../components/header/header"
import AddUpdate from "../product/add-update";
const { Content, Footer, Sider } = Layout;
class Admin extends Component {
  render() {
    const user = storeutil.getUser();
    if (!user || !user._id) {
      return <Redirect to="/login" />;
    }
    return (
      <>
        <Layout style={{ minHeight: "100vh" }}>
          <Sider>
            <Leftnav />
          </Sider>
          <Layout>
            <Header ></Header>
            <Content>
              <Switch>
                <Redirect exact from="/" to="/home" />
                <Route path="/home" component={Home} />
                <Route path="/category" component={Category} />
                <Route path="/product/addupdate" component={AddUpdate} />
                <Route path="/product" component={Product} />
                <Route path="/user" component={User} />
                <Route path="/role" component={Role} />
                <Route path="/charts/line" component={Line} />
                <Route path="/charts/pie" component={Pie} />
                <Route path="/charts/bar" component={Bar} />
              </Switch>
            </Content>
            <Footer style={{ textAlign: "center" }}></Footer>
          </Layout>
        </Layout>
      </>
    );
  }
}

export default Admin;
